package com.example.searchcenter.center;


import java.util.ArrayList;
import java.util.List;

import com.example.searchcenter.helper.ImageLoader;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
 
public class ImageAdapter extends BaseAdapter {
    private Context mContext;
    // Keep all Images in array
    public String[] mThumbIds = {
           
    };
    private LayoutInflater inflater;
    ImageLoader iloader;
    private static String url_image = "https://tinhnguyen.edu.vn/public/img/places/thumbs/";
    public List<ImageItem> arrayImage = new ArrayList<ImageItem>();
    // Constructor
    public ImageAdapter(Context c, List<ImageItem> array){
        this.mContext = c;
        this.arrayImage = array;
    }
 
    @Override
    public int getCount() {
        //return mThumbIds.length;
    	return this.arrayImage.size();
    }
 
    @Override
    public Object getItem(int position) {
        //return mThumbIds[position];
    	return this.arrayImage.get(position);
    }	
 
    @Override
    public long getItemId(int position) {
        return position;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(mContext);
        if(convertView == null){
        	  
              imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
              imageView.setLayoutParams(new GridView.LayoutParams(200, 200));
              imageView.setPadding(5, 5, 5, 5);
        }
        else{
        	imageView = (ImageView) convertView;
        }
        iloader = new ImageLoader(mContext);
        iloader.DisplayImage(url_image+arrayImage.get(position).getName(), imageView);
        
        return imageView;
    }
 
}